#include "dna.h"

std::string& conv2string (DnaSeq seq, std::string& str)
{
	for (int i=0 ; i < seq.len; i++)
		str = str + (char)Nucl(GET_NUCLEOTIDE(seq.nucl[NUCL_ARRAY_POS(i)], NUCL_CHAR_POS(i)));
	return str;
}


void fillDnaSeq(DnaSeq * seq, unsigned int f, unsigned int l, char * tab)
{
	seq->flag = f;
	seq->len = l;

	unsigned int nbchar = (l%4) ? l/4+1 : l/4;
	for (unsigned int i=0; i<nbchar; i++)
	{
		seq->nucl[i] = tab[i];
	}
}

std::ostream& operator<<(std::ostream& out, DnaSeq * seq)
{
	out << "flag : " << seq->flag << " " << std::endl;
	out << "len : " << seq->len << " " << std::endl;
	out << "nucl : ";
	unsigned int nbchar = seq->len / 4;
	unsigned int reste = seq->len % 4;

	// chars complets
	for (unsigned int i=0; i < nbchar; i++)
	{
		for (unsigned int j=0; j <= 3; j++)
		{
			out << Nucl((int)GET_NUCLEOTIDE(seq->nucl[i], j)).operator char();
		}
	}

	// dernier char incomplet
	if (reste)
	{
		for (unsigned int j=0; j < reste; j++)
		{
			out << Nucl((int)GET_NUCLEOTIDE(seq->nucl[nbchar], j)).operator char();
		}
	}

	out << std::endl;
	return out;
}

